	//根据选择的套表
	function initTreePanels(ids){
		var xmlLbales = ['A','B','C','D','E','F','G','H','I','G','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
		var xmlIds = [];
		if(trim(ids)==''){
			//没传ids时直接返回
			return;
		}
		var ids = ids.split(',');
		for(var i = 0;i<ids.length;i++){
			xmlIds.push({key:xmlLbales[i],value:ids[i]});
			Ext.getCmp('treepanels').add({
				id: 'tree-panel'+i,
				xmlId:ids[i],
				xmlLabel:xmlLbales[i],
				selModel:new Ext.tree.MultiSelectionModel(),
				title: '套表'+xmlLbales[i],
				//tools:tools,
				ddGroup: 'DDGroup',
				enableDrag:true,
				xtype: 'treepanel',
				useArrows:true,
				rootVisible : false,
				root: {text: '指标分类',draggable: false,id: '-1',isRoot:true},
				tbar:['->','-',{
					text:'选择套表',
					iconCls: 'book',
					handler:function(){
						Ext.getCmp('winId').show();
					}
				}],
				loader: new Ext.tree.TreeLoader({ 
						xmlId:ids[i],
						treeId:'tree-panel'+i,
						dataUrl: '${pageContext.request.contextPath}/summaryReport.report?decorate=no',
						listeners:{beforeload:function(treeLoader, node){
								if(node.attributes.isRoot==true){
									this.baseParams.method = "getRoot";
								}else{
									this.baseParams.method = "getChilds";
								}
								this.baseParams.treeId = this.treeId;
								this.baseParams.xmlId = this.xmlId;
								this.baseParams.tableName = node.attributes.table;
								this.baseParams.pid = node.attributes.val;
								this.baseParams.level = node.attributes.level;
								this.baseParams.dir = node.attributes.d;
								this.baseParams.time = node.attributes.time;
								this.baseParams.currentTime = jQuery("#currentTime").val();
								this.baseParams.currentTimeWeiBiao = jQuery("#currentTimeWeiBiao").val();
					   }}
				}),
				listeners:{
					startdrag:function(o,n,e){
						openLock();
					},
					contextmenu:function(node,e){
						if(node.attributes.d=='v'){
							showmenuAllV(node);
						}else if(node.attributes.d=='h'){
							showmenuAllH(node);
						}
					},
					afterrender:function(){
						this.root.expand();
					}
				}
				});
		}
		jQuery('#xmlIds').val(Ext.encode(xmlIds));
		Ext.getCmp('treepanels').setActiveTab(0);
		return Ext.encode(xmlIds);
	}
	function writeCondition(text){
		var tc = Ext.getDom("selColumnCondition_simple_conditions_");
	    var tclen = tc.value.length;
	    tc.focus();
	    if(typeof document.selection != "undefined")
	    {
	        document.selection.createRange().text = text;  
	    }
	    else
	    {
	        tc.setValue(tc.value.substr(0,tc.selectionStart)+text+tc.value.substring(tc.selectionStart,tclen));
	    }
	}

	function addquery(o,sqlTextareaId,column){
	    var tc = Ext.getDom(sqlTextareaId);
	    var tclen = tc.value.length;
	    tc.focus();
	    var str=o.text;
	    if(column)
	    	str+="("+column+")";
	    if(typeof document.selection != "undefined")
	    {
	        document.selection.createRange().text = str;  
	    }
	    else
	    {
	        tc.setValue(tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen));
	    }
	}
	
	//固定报告期年下拉列表
 	function getYear(yearId){
 		var year=new Date().format("Y");
 		var yearArray = new Array(); 
 		for(var i=0;i<21;i++){
				yearArray[i]=new Array();
				yearArray[i][0]=(year+i-15)+"年";
				yearArray[i][1]=(year+i-15);
 		}
 		var com_ds_year = new Ext.data.SimpleStore({    
 			fields:["name","valtext"],   
 			data:yearArray  
 		});   
 		var comboBox_year = new Ext.form.ComboBox({
 			id:yearId,
 			anchor:"83%",
 			selectOnFocus : true,	 
 			fieldLabel:'选择年份',	
 			editable:false,
 			store:com_ds_year,
 			triggerAction: "all",  //不加该语句选中某项后
 			mode: "local",   //动态需要	
 			displayField: "name",
 			valueField: "valtext",
 			value:yearArray[15][1]
 			});	
			return comboBox_year;		
 	}
 	
 	//钻取明细
 	function cellClickFn( gridId, rowIndex, columnIndex){
 		var xmlIds = initTreePanels(xml_id_);
 		var grid = Ext.getCmp(gridId);
		var ds = grid.getStore();
		var cm = grid.getColumnModel();
		var colname = cm.getColumnHeader(columnIndex); //获取列名   
		var record = ds.getAt(rowIndex);    //获得行记录
		var rowname = record.get('label'); 
		Ext.Ajax.request({
			url:'${pageContext.request.contextPath}/detailReport.report?method=drillToDetail',
			method:'post',
			params:{
				currentTimeDetail:currentTimeDetail,
				currentTimeDetailWB:currentTimeDetailWB,
				xmlIds:xmlIds,
				colName:colname,
				conditions:jQuery('#conditions').val(),
				kaohekoujing:jQuery('#kaohekoujing_').val(),
				rowContent:rowArray[rowIndex]['dimension'],
				rowConditions:rowArray[rowIndex]['conditions'],
				colContent:colArray[columnIndex]
			}, 
			success: function(response,options){
				var responseArray = Ext.util.JSON.decode(response.responseText);
				var grid_detail = new Grid({
					id:'grid_detail',
					height: 500,
					width:1200,
					pageSize:20,
					isForceFit:true,
					isPage:true,
					isRemoteExport:false,
				   title:"维度："+rowname,
				   key:'summaryDrillToDetail',
				   baseParams:{drillSql:responseArray.sql},	
				   singleSelect:false,
				   autoScroll:true,
				   callback:function(cm){
					   
				   }
				});
				
				var grid_detail_win = new Ext.Window(	
				{	
					width:1220,	
					height: 530,
					title:'指标：'+colname,
					modal: true,
					border:false,
					id: "grid_detail_win",
					closeAction: 'close',
					items: [grid_detail]
				});
				grid_detail_win.show();
		 	}
		});
 	}
 	
	//----------------锁定和解锁钻取功能开始--------------------
	function drillToDetail(gridId,flag)
	{   
		if(flag==""){//点按钮
			drillFlag = !drillFlag;
		}
		else{//点预览
			drillFlag = !flag;
		}
		var grid =  Ext.getCmp(gridId);
		var ds = grid.getStore();
		var cm = grid.getColumnModel();
		//设置单元格是否能编辑----false不能编辑，true可编辑
		if(drillFlag) {//开启
			jQuery("#drillToDetail").attr("src",getRootPath()+"/images/report/icon_loading.gif");
		}
		else {
			jQuery("#drillToDetail").attr("src",getRootPath()+"/images/report/icon_loading_un.gif");
		}
		cm.isCellEditable = function(col, row) {
			if(drillFlag) {//开启
				return false;
			}
			else {
				return true;
			}
		}
		//遍历每列，非空值添加钻取图片和方法，空值保持原样
		for(var i=1;i<cm.getColumnCount(true);i++){
			cm.setRenderer(i,function(value,data,record,row,col){
				if(drillFlag&&value!=""&&value!="-"&&value!="0"&&colArray[col]!='customH')
					return "<img src='"+getRootPath()+"/images/report/down.gif' style='cursor:pointer;' onclick='cellClickFn(\""+gridId+"\","+row+","+col+")'></img>"+value;
				else 
					return value;
			});
		}
		grid.reconfigure(ds,cm);
	}
